package com.changxianggu.cloud.crawler.core.modules.university.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.changxianggu.cloud.crawler.core.modules.university.entity.UniversityBook;
import com.changxianggu.cloud.crawler.core.modules.university.mapper.UniversityBookMapper;
import com.changxianggu.cloud.crawler.core.modules.university.service.IUniversityBookService;
import com.changxianggu.cloud.crawler.core.config.mybatisplus.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 教材信息表 服务实现类
 * </p>
 *
 * @author liuyuantao
 * @since 2020-02-20
 */
@Service
@DS("university")
public class UniversityBookServiceImpl extends BaseServiceImpl<UniversityBookMapper, UniversityBook> implements IUniversityBookService {
    @Override
    public int queryCountByIsbn(String isbn) {
        QueryWrapper<UniversityBook> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ISBN", isbn);
        return this.baseMapper.selectCount(queryWrapper);
    }

    @Override
    public void saveEntity(UniversityBook entity) {
        this.baseMapper.insert(entity);
    }

    @Override
    public void updateEntityByIsbn(UniversityBook entity) {
        UpdateWrapper<UniversityBook> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("ISBN", entity.getBookIsbn());
        this.baseMapper.update(entity, updateWrapper);
    }
}
